package com.jhs.boot.runner;

import com.jhs.boot.common.beans.Common;
import com.jhs.boot.config.FeignClientFactory;
import com.jhs.boot.system.mapper.SysRouteMapper;
import com.jhs.boot.system.model.entity.SysRoute;
import com.jhs.boot.system.service.FeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.awt.*;
import java.util.List;

/**
 * @Classname RouteInitializer
 * @Description TODO
 * @Date 2025/11/24 14:44
 * @Created by zxy
 */
@Component
public class RouteInitializer implements CommandLineRunner {


    @Autowired
    private SysRouteMapper sysRouteMapper;

    @Autowired
    private FeignClientFactory feignClientFactory;
    @Override
    public void run(String... args) throws Exception {
        // 系统启动时加载所有路由并初始化Feign客户端
        List<SysRoute> routes = sysRouteMapper.selectList(null);
        for (SysRoute route : routes) {
            String baseUrl = Common.HTTP + route.getRouteIp() + ":" + route.getPort();
                // 这里只是触发缓存， 在getFeignClient中 缓存
            FeignService feignClient = feignClientFactory.getFeignClient(baseUrl);
            System.out.println("SZ");
        }
    }
}